package com.ym.b2b.commons.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.apache.log4j.Logger;

import com.ym.b2b.cache.configcache.WebAppConfig;
import com.ym.b2b.cache.configcache.WebAppConfigUtil;
import com.ym.b2b.commons.util.FileUtil;
import com.zc.export.Constants;
import com.zc.export.XMLUtil;

@WebListener("This is only a demo listener")
public class AppStartListener implements ServletContextListener {

    private Logger logger = Logger.getLogger(getClass());

    @Override
    public void contextDestroyed(ServletContextEvent event) {

    }

    @Override
    public void contextInitialized(ServletContextEvent event) {
        try {
            Constants.APP_PATH = event.getServletContext().getRealPath("/");

            // 载入excel 配置
            XMLUtil xmlUtil = new XMLUtil();
            xmlUtil.loadConfig(Constants.APP_PATH + "export/config.xml");

            // 载入动态策略配置
            WebAppConfig.APP_PATH = event.getServletContext().getRealPath("/");
            WebAppConfig.CLASS_PATH = getClass().getResource("/").toString();
            WebAppConfigUtil a = new WebAppConfigUtil();
            a.readConfig();

            // 删除文件
            FileUtil.delAllFile(Constants.APP_PATH + "export/load/");

            // lincesss 验证

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("- 读取 系统配置 异常,请检查路径" + e.getMessage());
        }
    }

}
